<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib" prefix="frame"%>
  <head>
	<title>公共平台 </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!-- 样式文件的引入 -->
	<link href="${ctx}/commons/css/style.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/icon.css">
	<!-- jqueryUI JS文件的引入 -->
	<script type="text/javascript" src="${ctx}/commons/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${ctx}/commons/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/commons/js/easyui-extends-validate.js"></script>
	<!-- jqueryUI国际化 -->
	<script type="text/javascript" src="${ctx}/commons/js/easyui-lang-zh_CN.js"></script>
	<!-- 开发使用的公用js方法 -->
	<script type="text/javascript" src="${ctx}/commons/js/common.js"></script>
	<!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
	<script type="text/javascript">var ctx = '${ctx}';var actionExt = "action";var i18n = new Object();</script>
	<script src="${ctx}/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
  </head>
  
  <body>
    <div class="easyui-layout" data-options="fit:true,border:false" >
    	<div data-options="region:'north',border:false" style="padding: 4px;height: 50px;overflow: hidden;">
    	<div class="easyui-panel" data-options="fit:true,border:true" >
    	<div  class="queryContent">
			<form name="searchProjectsForm" id="searchProjectsForm" method="post" action="" style="display: none; ">
				<table class="queryTable" >
					<tbody>
						<tr>
							<th >项目名称</th>
							<td width="10%">
								<input id="projectName" class="easyui-validatebox" type="text" name="projectName"  maxlength="50" style="width:120px;height: 15px;"/>
							</td>
							<th >单位名称</th>
							<td>
								<input id="companyName" class="easyui-validatebox" type="text" name="companyName"  maxlength="50" style="width:120px;height: 15px;"/>
							</td>
							<th>缴纳时间</th>
							<td>
								<input id="startTime" class="easyui-datebox" type="text" name="transTimeStart"  data-options="validType:['dateTimeLessCompare[\'stopTime\']']" maxlength="20" style="width:120px;height: 25px;"/>-<input id="stopTime" class="easyui-datebox" type="text"  data-options="validType:['dateTimeMoreCompare[\'startTime\']']" name="transTimeEnd" maxlength="20" style="width:120px;height: 25px;"/>
							</td>
							<td align="right">
								<a href="javascript:void(0);" class="easyui-linkbutton" id="searchProjects" iconcls="icon-search" plain="true">查询</a>
								<a href="javascript:void(0);" class="easyui-linkbutton" id="resetsearchProjects" iconcls="icon-reset" plain="true">清空</a>
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
    	</div>
    	</div>
		<div data-options="region:'center',border:false" style="padding: 4px;">
			<table id="mydialog" class="easyui-datagrid" 
					data-options="singleSelect:false,method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
						pagination:true,multiSort:true,remoteSort:true,striped:true,height:300,
						url:'${ctx}/biz/return2/list'">
				<thead>
					<tr>
						<th data-options="field:'pk',width:150,title:'单位名称',formatter:fromatterCompanyName" align="center"></th>
						<th data-options="field:'projectName',width:150,title:'项目名称',sortable:true" align="center"></th>
						<th data-options="field:'tnAmount',width:100,title:'缴纳金额',sortable:true" align="center"></th>
						<th data-options="field:'transTime',width:150,title:'缴纳时间',sortable:true" align="center"></th>
						<th data-options="field:'hstSeqNum',width:150,title:'交易流水号',formatter:fromatterHstSeqNum" align="center"></th>
						<th data-options="field:'inAcct',width:150,title:'投标人账户'" align="center"></th>
						<th data-options="field:'returnOpt',width:80,title:'是否提交退还申请',sortable:true,formatter:formatOpt" align="center"></th>
						<th data-options="field:'addWord',width:80,title:'中间状态',sortable:true"align="center"></th>
						<th data-options="field:'status',width:80,title:'退还状态',sortable:true,formatter:formatStatus" align="center"></th>
						<th data-options="field:'operation',width:80,title:'操作',formatter:formatbutton" align="center"></th>
					</tr>
				</thead>
			</table>
         </div>
      </div>
</body>
	<script type="text/javascript">
	
	//初始化表格对应的js对象
	var projectsParamObj;
	$(function() {
		//初始化表格对象数据
		projectsParamObj = new initParams(
				{
					paramObjName : 'projectsParamObj',//表格对应的实体对象名称，好区分多个表格情况下的对象
					tableId:'mydialog',
					addDataFormId:'addProjectsDataForm',
					showDialogId:'firstLevelDialog',
					searchID:'searchProjects',
					resetSearchID:'resetsearchProjects',
					searchFormID:'searchProjectsForm',
					//updateUrl:"${ctx}/business/projectmanage/input?projectId=",
					//deleteUrl:'${ctx}/business/projectmanage/remove',
					addDialogWidth:700,
					addDialogHeight:520,
					ctx:'${ctx}',
					addDialogTitle:'采购项目信息'
				});
		//初始化查询
		init(projectsParamObj);
		
	});
	
	
     	var projectId=$("#projectId").val();        
	    // 是否投标格式化  
		function formatStatus(val, row, index) {
			if (row.status == 0) {
				return '<font color="blue">未退还</font>';
			} else if (row.status == 1) {
				return '<font color="green">已退还</font>';
			} else if (row.status == 2) {
				return '<font color="red">扣除</font>';
			}else if(row.status==-1){
				return '<font color="orange">退还失败</font>';
			}

		}

		//是否提交申请格式化	    
		function formatOpt(val, row, index) {
			if (row.returnOpt == 0) {
				return '<font color="blue">未申请</font>';
			} else if (row.returnOpt == 1) {
				return '<font color="green">申请成功</font>';
			}else if (row.returnOpt == -1){
				return '<font color="orange">申请超时</font>';
			}else if(row.returnOpt == 2){
				return '<font color="red">申请失败</font>';
			}
		}
/*
		//是否投标    
		function formatBid(val, row, index) {
			if (row.bid == false) {
				return '<font color="red">未投标</font>';
			} else if (row.bid == true) {
				return '<font color="green">已投标</font>';
			}
		}*/

		//单位名
		function fromatterCompanyName(val, row, index) {
			if (row.pk) {
				return row.pk.companyName;
			}
		}
		
		//流水号
		function fromatterHstSeqNum(val, row, index) {
			if (row.pk) {
				return row.pk.hstSeqNum;
			}
		}
		
		//操作按钮
	   	function formatbutton(val, row, index){
    	   if(row.status!=1&&row.returnOpt != 1){
    		   return '<button  onclick="returnUnBidDeposit(\'' + row.pk.projectId+ '\',\'' + row.pk.companyName+ '\',\'' + row.pk.hstSeqNum+ '\',\'' + row.pk.depositType+ '\')" class=""><font color="green">退还</font></button>';
    	   }else {
    		   return '<button  onclick="" disabled="true" class=""><font color="red">退还</font></button>';	
    	   }
   	 	}
	 	//操作按钮(中标)
/*
	 	function formatbutton2(val, row, index){
    	   if(row.status!=1){
    		   return '<button  onclick="returnBidDeposit(\'' + row.pk.projectId+ '\',\'' + row.bidderId+ '\')" class=""><font color="green">退还</font></button>';	
    	   }else {
    		   return '<button  onclick="" disabled="true" class=""><font color="red">退还</font></button>';	
    	   }
       	}

		// 完成保证金操作
		function finishDepositReturnt() {
			$.ajax({type : 'post',
				url : '${ctx}/business/projectmanage/leader/getReturnList',
				data : {
					projectId : $("#projectId").val()
				},
				success : function(data) {
					if (data == "unPass") {
						$.messager.alert('提示信息','存在已提交退款申请，银行未完成退还的状态！','error');
					} 
					else if (data == "allreturn") {
						$.messager.confirm('提示信息','是否确认保证金退还操作完成？',
							function(r) {
								if (r) {
									$.ajax({
										type : 'post',
										url : '${ctx}/business/projectmanage/leader/finishDepositReturn',
										data : {
											projectId : $("#projectId").val()
										},
										success:function(){
											top.$('#threeLevelDialog').dialog('close');
											
										},

									});
								}
							});
					} 
					else if (data == "unallreturn") {
						$.messager.confirm('提示信息','本项目尚存在未退还保证金，是否确认扣除这些投标人的保证金并完成保证金退还操作？',
							function(r) {
								if (r) {
									$.ajax({
										type : 'post',
										url : '${ctx}/business/projectmanage/leader/finishDepositReturn',
										data : {
											projectId : $(
													"#projectId")
													.val()
										},
										success:function(){
											top.$('#threeLevelDialog').dialog('close');
											
										},
									});
								}
							});
					}
				}
			});

		}

		*/
		
     	//退还非中标保证金
		function returnUnBidDeposit(projectId,companyName,hstSeqNum,depositType) {
			$.messager.confirm('确认对话框','是否退还保证金？',
				function(r) {
					if(r){
						loading();//加载数据loading
						$.ajax({    
							type : 'post',
							url : '${ctx}/biz/return2/returnDeposit',
							data : {
								projectId : projectId,
								companyName : companyName,
								hstSeqNum:hstSeqNum,
								depositType:depositType
							},
							success : function(data) {
								if(data=="bankTimeOut"){
									top.$.messager.alert('提示信息','银行超时无响应！','error',function(){
										top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
										$('#mydialog').datagrid('reload');	
									 });
								}else if(data=="noExecuteDeposit"){
									top.$.messager.alert('提示信息','未缴纳履约保证金，无法退还中标保证金！','error',function(){
										top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
										$('#mydialog').datagrid('reload');	
									 });
								}else if(data=="saveSuccess"){
									top.$.messager.alert('提示信息','退还申请成功,请等待银行处理结果！','info',function(){
										top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
										$('#mydialog').datagrid('reload');	
									 });
								}else if(data=="saveUnsuccess"){
									top.$.messager.alert('提示信息','退还申请失败，请确认后重新提交申请！','error',function(){
										top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
										$('#mydialog').datagrid('reload');	
									 });
								}
							
							}
						});
					}
				});
		    }
		
        //退还中标保证金
/*
		function returnBidDeposit(projectId,bidderId) {
			$.messager.confirm('确认对话框','是否退还保证金？',
				function(r) {
				  if(r){
					//加载数据loading
					loading();
					$.ajax({   
						type : 'post',
						url : '${ctx}/business/projectmanage/leader/returnDeposit',
						data : {
							projectId : projectId,
							projectName : null,
							bidderId:bidderId
						},
						success : function(data) {
							if(data=="bankTimeOut"){
								top.$.messager.alert('提示信息','银行超时无响应！','error',function(){
									top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
									$('#mydialog2').datagrid('reload');	
								 });
							}else if(data=="noExecuteDeposit"){
								top.$.messager.alert('提示信息','未缴纳履约保证金，无法退还中标保证金！','error',function(){
									top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
									$('#mydialog2').datagrid('reload');	
								});
							}else if(data=="saveSuccess"){
								top.$.messager.alert('提示信息','退还申请成功,请等待银行处理结果！','info',function(){
									top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
									$('#mydialog2').datagrid('reload');	
								 });
							}else if(data=="saveUnsuccess"){
								top.$.messager.alert('提示信息','退还申请失败，请确认后重新提交申请！','error',function(){
									top.$('#secondtLevelDialog').dialog('close');//关闭加载数据
									$('#mydialog2').datagrid('reload');	
								 });
							}
						
						}
					});
				  }
				});
			}


*/
		 function loading(){
			top.$('#secondtLevelDialog').dialog({
			closable: false,
			title:'数据加载',
			width: '300',    
			height: '180',    
			closed: false,    
			inline : true,
			cache: false,    
			href: "${ctx}/commons/js/loading/loading.html",
			modal: true,
			extractor : function(data){
				if($.trim(data) == "unLogin"){
					var msn = ''||i18n[''];
					msn = msn||i18n[data];
					if(msn != undefined){
						top.$.messager.alert('提示',msn,'info',function(){top.location='${ctx}/user-login-sys-new/loginPwd';});
						return '';
					}
				}
				return data;
			}
			});
			top.$('#secondtLevelDialog').dialog("center");
			}
	</script>